home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / BTREE_.H < prev    next >
Text File  |  1991-09-23  |  5KB  |  168 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /*man---------------------------------------------------------------------------
  5. NAME
  6.      btree_.h - private header file for btree library
  7.  
  8. SYNOPSIS
  9.      #include "btree_.h"
  10.  
  11. DESCRIPTION
  12.      This is a private header file included by the btree library
  13.      modules.  It contains function declarations and macros for
  14.      internal use by the btree library.
  15.  
  16. ------------------------------------------------------------------------------*/
  17. #ifndef H_BTREE_    /* prevent multiple includes */
  18. #define H_BTREE_
  19.  
  20. /* #ident    "@(#)btree_.h    1.5 - 91/09/23" */
  21.  
  22. #include <ansi.h>
  23.  
  24. /*#define DEBUG        /* switch to enable debugging for btree library */
  25.  
  26. /* ansi headers */
  27. #ifdef AC_STRING
  28. #include <string.h>
  29. #endif
  30.  
  31. #include <bool.h>
  32.  
  33. /* local headers */
  34. #include "btree.h"
  35.  
  36. /* type definitions */
  37. typedef struct {        /* (key, child) tuple */
  38.     void *    keyp;        /* pointer to single key */
  39.     bpos_t    child;        /* child link */
  40. } bttpl_t;
  41.  
  42. /* tables */
  43. extern btree_t btb[BTOPEN_MAX];    /* btree control structure table declaration */
  44.  
  45. /* bthdr_t bit flags */
  46. #define BTHMOD          (01)    /* btree file being modified */
  47.  
  48. /* btree_t bit flags */
  49. #define BTOPEN          (03)    /* open status bits */
  50. #define BTREAD          (01)    /* btree is open for reading */
  51. #define BTWRITE          (02)    /* btree is open for writing */
  52. #define BTLOCKS         (030)    /* lock status bits */
  53. #define BTRDLCK         (010)    /* btree is read locked */
  54. #define BTWRLCK         (020)    /* btree is write locked */
  55. #define BTERR        (0100)    /* error has occurred on this btree */
  56.  
  57. /* function declarations */
  58. #ifdef AC_PROTO
  59. int        bt_alloc(btree_t *btp);
  60. int        bt_delete(btree_t *btp);
  61. void        bt_free(btree_t *btp);
  62. bool        bt_fvalid(size_t keysize, int fldc, const btfield_t fldv[]);
  63. int        bt_grow(btree_t *btp, const bttpl_t *bttplp);
  64. int        bt_search(btree_t *btp, const void *buf);
  65. int        bt_shrink(btree_t *btp, const bpos_t *newrootp);
  66. bool        bt_valid(btree_t *btp);
  67.  
  68. btnode_t *    bt_ndalloc(btree_t *btp);
  69. int        bt_ndcopy(btree_t *btp, btnode_t *tbtnp, const btnode_t *sbtnp);
  70. int        bt_nddelkey(btree_t *btp, btnode_t *btnp, int kn);
  71. void        bt_ndfree(btnode_t *btnp);
  72. int        bt_ndfuse(btree_t *btp, btnode_t *lbtnp, btnode_t *rbtnp,
  73.             btnode_t *pbtnp, int pkn);
  74. int        bt_ndget(btree_t *btp, bpos_t node, btnode_t *btnp);
  75. void        bt_ndinit(btree_t *btp, btnode_t *btnp);
  76. int        bt_ndinskey(btree_t *btp, btnode_t *btnp, int kn,
  77.             const bttpl_t *bttplp);
  78. int        bt_ndput(btree_t *btp, bpos_t node, const btnode_t *btnp);
  79. int        bt_ndsearch(btree_t *btp, const btnode_t *btnp, const void *buf,
  80.             int *knp);
  81. int        bt_ndshift(btree_t *btp, btnode_t *lbtnp, btnode_t *rbtnp,
  82.             btnode_t *pbtnp, int pkn, bpos_t pnode);
  83. int        bt_ndsplit(btree_t *btp, bpos_t node, btnode_t *btnp,
  84.             btnode_t *rbtnp, bttpl_t *bttplp);
  85.  
  86. int        bt_kymvleft(btree_t *btp, btnode_t *lbtnp, btnode_t *rbtnp,
  87.             int nm);
  88. int        bt_kymvright(btree_t *btp, btnode_t *lbtnp, btnode_t *rbtnp,
  89.             int nm);
  90. int        bt_kyread(btree_t *btp, const btnode_t *btnp, int kn,
  91.             bttpl_t *bttplp);
  92. int        bt_kyshift(btree_t *btp, btnode_t *btnp, int kn, int ns);
  93. int        bt_kywrite(btree_t *btp, btnode_t *btnp, int kn,
  94.             const bttpl_t *bttplp);
  95.  
  96. void        bt_dgbtp(btree_t *btp, FILE *fp);
  97. int        bt_dgbtree(btree_t *btp, bpos_t node, FILE *fp);
  98. void        bt_dgnode(btree_t *btp, btnode_t *btnp, FILE *fp);
  99. void        bt_dgtuple(btree_t *btp, bttpl_t *bttplp, FILE *fp);
  100. #else
  101. int        bt_alloc();
  102. int        bt_delete();
  103. void        bt_free();
  104. bool        bt_fvalid();
  105. int        bt_grow();
  106. int        bt_search();
  107. int        bt_shrink();
  108. bool        bt_valid();
  109. btnode_t *    bt_ndalloc();
  110. int        bt_ndcopy();
  111. int        bt_nddelkey();
  112. void        bt_ndfree();
  113. int        bt_ndfuse();
  114. int        bt_ndget();
  115. void        bt_ndinit();
  116. int        bt_ndinskey();
  117. int        bt_ndput();
  118. int        bt_ndsearch();
  119. int        bt_ndshift();
  120. int        bt_ndsplit();
  121. int        bt_kymvleft();
  122. int        bt_kymvright();
  123. int        bt_kyread();
  124. int        bt_kyshift();
  125. int        bt_kywrite();
  126. void        bt_dgbtp();
  127. int        bt_dgbtree();
  128. void        bt_dgnode();
  129. void        bt_dgtuple();
  130. #endif    /* #ifdef AC_PROTO */
  131.  
  132. /* macros */
  133. #define bt_blksize(BTP) ((size_t)(                    \
  134.     offsetof(btnode_t, keyv) +                    \
  135.     ((BTP)->bthdr.m - 1) * (BTP)->bthdr.keysize +            \
  136.     (BTP)->bthdr.m * sizeof(bpos_t)                    \
  137. ))
  138. #define    bt_ndleaf(BTNP)    (*bt_kychildp(BTNP, 0) == NIL)
  139. #define    bt_ndmax(BTP)    ((int)((BTP)->bthdr.m - 1))
  140. #define    bt_ndmin(BTP)    ((int)((((BTP)->bthdr.m + 1) / 2) - 1))
  141. #define bt_kychildp(BTNP, N) ((bpos_t *)(                \
  142.             (char *)(BTNP)->childv +            \
  143.             (size_t)(N) * sizeof(bpos_t)            \
  144. ))
  145. #define bt_kykeyp(BTP, BTNP, N) ((void *)(                \
  146.             (char *)(BTNP)->keyv +                \
  147.             ((size_t)(N) - 1) * (BTP)->bthdr.keysize    \
  148. ))
  149. #define bt_kykfp(BTP, BTNP, N, F) ((void *)(                \
  150.             (char *)bt_kykeyp((BTP), (BTNP), (N)) +        \
  151.             (BTP)->fldv[(F)].offset                \
  152. ))
  153.  
  154. /* btree open types */
  155. #define BT_READ        ("r")
  156. #define BT_RDWR        ("r+")
  157.  
  158. #ifdef DEBUG
  159. #define    BTEPRINT {                            \
  160.     fprintf(stderr, "*** btree error line %d of %s.  errno = %d.\n",\
  161.         __LINE__, __FILE__, errno);                \
  162. }
  163. #else
  164. #define BTEPRINT
  165. #endif
  166.  
  167. #endif        /* #ifndef H_BTREE_ */
  168.